//
//  QXUser.swift
//  QXWeibo
//
//  Created by QinXin on 15/6/30.
//  Copyright © 2015年 labi3285_Lab. All rights reserved.
//

import UIKit

class QXUser: NSObject {
    
    /// 用户 uid
    var id: Int = 0
    /// 显示名称
    var name: String?
    /// 头像地址 50 x 50
    var profile_image_url: String? {
        didSet {
            profileURL = NSURL(string: profile_image_url!)
        }
    }
    /// 是否为认证用户
    var verified: Bool = false
    /// 认证类型 -1:无认证 0: 认证 2、3、5：企业认证 22:达人
    var verified_type: Int = -1
    /// vip级别
    var mbrank: Int = 0

    
    var profileURL: NSURL?
    var verifiedImage: UIImage? {
        switch verified_type {
        case 0:
            return UIImage(named: "avatar_vip")
        case 2,3,5:
            return UIImage(named: "avatar_grassroot")
        case 220:
            return UIImage(named: "avatar_enterprise_vip")
        default:
            return nil
        }
    }
    var mbImage: UIImage? {
        if mbrank > 0 && mbrank < 7 {
            return UIImage(named: "common_icon_membership_level\(mbrank)")
        } else {
            return nil
        }
    }
    
    static let properties = [
        "id",
        "name",
        "profile_image_url",
        "verified",
        "verified_type",
        "mbrank",
    ]
    
    init(dic: [String: AnyObject]) {
        super.init()
        for key in QXUser.properties {
            if dic[key] != nil {
                setValue(dic[key], forKey: key)
            }
        }
    }
    
    override var description: String {
        let dic = dictionaryWithValuesForKeys(QXUser.properties)
        return "\(dic)"
    }
    

}
